<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"  @submit.native.prevent @keyup.enter.native="handleQuery">
      <el-form-item label="申请人" prop="qKey">
        <el-input v-model="queryParams.qKey" placeholder="姓名" clearable></el-input>
      </el-form-item>
      <el-form-item label="部门" prop="qIds1">
        <el-cascader
          v-model="queryParams.qIds1"
          :options="deptList"
          :props="{value: 'id',children: 'children',label: 'label',expandTrigger:'hover'}"
          filterable
          clearable
          placeholder=""
          style="width: 400px;"
        ></el-cascader>
      </el-form-item>
      <el-form-item label="申请时间" prop="qTimeStartList">
        <el-date-picker
          v-model="queryParams.qTimeStartList"
          type="daterange"
          range-separator="-"
          start-placeholder="起"
          end-placeholder="止"
          value-format="yyyy-MM-dd"
        ></el-date-picker>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <router-link class="link-type" :to="'/points/poi-apply-add/add/0'" v-hasPermi="['points:poiApply:add']">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
          >新增</el-button>
        </router-link>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['points:poiApply:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table ref="tables" v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" @sort-change="handleSortChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="nickName" fixed/>
      <el-table-column label="部门" align="center" prop="deptName" width="200"/>
      <el-table-column label="申请积分" align="center" prop="score" />
      <el-table-column label="申请项目数" align="center" prop="numItem" />
      <el-table-column label="申请时间" align="center" prop="timeStart" />
      <el-table-column label="申请状态" align="center" prop="applyStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.apply_status" :value="scope.row.applyStatus"/>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width"  width="150">
        <template slot-scope="scope">
          <router-link class="link-type" :to="'/points/poi-apply-add/add/'+scope.row.id" v-hasPermi="['points:poiApply:edit']">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
            >修改</el-button>
          </router-link>
          &emsp;
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['points:poiApply:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>


export default {
  name : "PoiApply",
  dicts: ['apply_status'],
  data() {
    return {
      deptList:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        qKey: "",
        qIds1: undefined,
        qTimeStartList: undefined,
        qStatus: undefined,
        pageNum: 1,
        pageSize: 10,
        isAsc:undefined,
        orderByColumn:undefined
      },
      dialogTableVisible:false,
    };
  },
  created() {
    //this.getList();
    this.getDepts();
  },
  activated() {
    this.getList();
  },
  methods: {
    getDepts(){
      this.request({
        url: '/system/user/deptTree',
        method: 'get',
      }).then(response => {
        this.deptList = response.data;
      });
    },
    getList() {
      this.loading = true;
      this.request({
        url: '/points/poiApply/list',
        method: 'get',
        params: this.queryParams
      }).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.isAsc = undefined;
      this.queryParams.orderByColumn = undefined;
      this.queryParams.pageNum = 1;
      this.$refs.tables.clearSort();
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = this.getLowLineCase(column.prop);
      this.queryParams.isAsc = column.order;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      let deleteIds = row && row.id || this.ids;
      this.$modal.confirm('是否确认删除？').then(() => {
        return this.request({
          url: '/points/poiApply/remove/' + deleteIds,
          method: 'delete'
        });
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch((err) => {
        console.log(err)
      });
    },
  }
};
</script>

